<?

/**
 * $Id: SharedController.php 1254 2008-09-09 08:39:51Z lule $
 *
 * Kontroler elementow wspolnych
 *
 */
class ServerController extends MainController implements ControllerInterface {

	public function IndexAction($param) {
		
	}

	public function preDispatch($param) {
		
	}

	public function postDispatch($param) {
		
	}

	/**
	 * Wyswietlanie obrazka captcha
	 */
	public function CaptchaAction() {
		//$this->disableTemplates = true;
		$this->SetAjaxRender();
		include(PATH_CORE . '/plugins/Captcha.php');
		$word = rand(2, 9) . rand(2, 9) . rand(2, 9) . rand(2, 9) . rand(2, 9);

		setcookie(CAPTCHA_COOKIE_NAME, (md5(strtolower($word) . CAPTCHA_SEED)));
		//session_start();
		//$_SESSION['captcha'] = $word;
		$image = confirm($word);
		$this->content = $image;
		//die();
	}

	/**
	 * Wyswietlanie obrazka captcha
	 */
	public function Captcha2Action() {
		//$this->disableTemplates = true;
		$this->SetAjaxRender();
		include(PATH_CORE . '/plugins/Captcha.php');
		$word = rand(2, 9) . rand(2, 9) . rand(2, 9) . rand(2, 9) . rand(2, 9);

		setcookie(CAPTCHA_COOKIE_NAME2, (md5(strtolower($word) . CAPTCHA_SEED)));
		//session_start();
		//$_SESSION['captcha'] = $word;
		$image = confirm($word);
		$this->content = $image;
		//die();
	}

	public function CheckCaptchaAction($param) {
		$this->SetAjaxRender();
		$this->SetNoRender();
		$word = Request::Get('captcha1');
		header('Content-type: application/json');
		echo json_encode($_COOKIE[CAPTCHA_COOKIE_NAME] == (md5(strtolower($word) . CAPTCHA_SEED)) ? true : false);
	}

	public function CheckCaptcha2Action($param) {
		$this->SetAjaxRender();
		$this->SetNoRender();
		$word = Request::Get('captcha2');
		header('Content-type: application/json');
		echo json_encode($_COOKIE[CAPTCHA_COOKIE_NAME2] == (md5(strtolower($word) . CAPTCHA_SEED)) ? true : false);
	}

}

?>